package com.qf.day06;

public class User {
    private String name;
    private int age;

    public void setName(String name){
        if(name.length()>3||name.length()<1){
            System.out.println("长度输入错误");

        }else {
            System.out.println(name.length());
            this.name = name;
        }
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }

    // 给age赋值
    public void setAge(int age){
        // 检查age的取值范围，合法范围在 [1,200]
        if (age<1 || age>200){
            System.out.println("年龄非法，使用默认年龄18岁");
            this.age = 18;
        }else {
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
